package com.heima.skydemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.skydemo.domin.common.PageResult;
import com.heima.skydemo.domin.dto.EmployeeLoginDTO;
import com.heima.skydemo.domin.dto.EmployeeQueryDTO;
import com.heima.skydemo.entity.Category;
import com.heima.skydemo.entity.Employee;
import com.heima.skydemo.mapper.EmployeeMapper;
import com.heima.skydemo.service.IEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 员工信息 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-15
 */
@Service
@Slf4j
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {


    public PageResult QueryPage(EmployeeQueryDTO employeeQueryDTO) {
        log.info("分页查询员工信息{}" + employeeQueryDTO);
        PageResult pageResult = new PageResult();
        //开始分页查询
        PageHelper.startPage(employeeQueryDTO.getPage(), employeeQueryDTO.getPageSize());
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper<Employee>().like(employeeQueryDTO.getName()!=null,Employee::getName, employeeQueryDTO.getName());
        Page<Employee> pageQuery = (Page<Employee>) list(wrapper);
        //查询结果
        pageResult.setTotal(pageQuery.getTotal());
        pageResult.setRecords(pageQuery.getResult());


        return pageResult;
    }
}
